{{ $.Scratch.Set "i-classes" (split (.Get "classes") " ") }}
{{ if in ($.Scratch.Get "i-classes") "clear" }} 
  {{ $.Scratch.Set "i-clear" 1 }}
  {{ $classes := $.Scratch.Get "i-classes" }}
  {{ $.Scratch.Set "i-classes" (slice) }}
  {{ range $classes }}
    {{ if ne . "clear" }}
      {{ $.Scratch.Add "i-classes" . }}
    {{ end }}
  {{ end }}
{{ end }}
{{ if in ($.Scratch.Get "i-classes") "fancybox" }} 
  {{ $.Scratch.Set "i-fancybox" 1 }}
  {{ $classes := $.Scratch.Get "i-classes" }}
  {{ $.Scratch.Set "i-classes" (slice) }}
  {{ range $classes }}
    {{ if ne . "fancybox" }}
      {{ $.Scratch.Add "i-classes" . }}
    {{ end }}
  {{ end }}
{{ end }}
<div class="figure {{ delimit ($.Scratch.Get "i-classes") " " }}" {{ with (.Get "thumbnailWidth") }}style="width:{{ . }};"{{ end }}>
  {{ if eq ($.Scratch.Get "i-fancybox") 1 }}
    <a class="fancybox" href="{{ .Get "src" }}"{{ with (.Get "title") }} title="{{ . }}"{{ end }} data-fancybox="{{ with (.Get "group") }}{{ . }}{{ end }}">
  {{ end }}
    <img class="fig-img" src="{{ with (.Get "thumbnail") }}{{ . }}{{ else }}{{ .Get "src" }}{{ end }}" {{ if or (.Get "thumbnail-width") (.Get "thumbnail-height") }}style="{{ with (.Get "thumbnail-width") }}width: {{ . }};{{ end }}{{ with (.Get "thumbnail-height") }}height: {{ . }};{{ end }}"{{ end }}{{ with (.Get "title") }} alt="{{ . }}"{{ end }}>
  {{ if eq ($.Scratch.Get "i-fancybox") 1 }}
    </a>
  {{ end }}
  {{ if and (.Get "title") (not (in ($.Scratch.Get "i-classes") "nocaption")) }} 
    <span class="caption">{{ .Get "title" }}</span>
  {{ end }}
</div>
{{ if eq ($.Scratch.Get "i-clear") 1 }}
  <div style="clear:both;"></div>
{{ end }}